<?php
//入库查询
class OutStoreApp extends MallbaseApp
{
    public $wxNum = 0;
    public function __construct()
    {
        parent::__construct();
        $this->wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($this->wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='index.php?app=login'; </script>  ";//使用weixin.php的页面
            exit();
        }


    }

    // 选择仓库
    function index()
	{
		$this->display('outstore.index.html');
	}

	// 获取接口信息
	private function api($method, $param) {
        try {
            if ($this->checkUrl(WEB_SERVICE2)) {
                $client = new soapclient(WEB_SERVICE2);
                $client->soap_defencoding = 'utf-8';
                $client->decode_utf8 = false;
                $client->xml_encoding = 'utf-8';

                $result = $client->$method($param);

                if (is_soap_fault($result)) {
                    trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
                } else {
                    $resultProperty = $method.'Result';
                    $result = json_decode(json_encode($result->$resultProperty), TRUE);
//                    if($method == 'GetStoreGoodsList') echo $result;
                    $result = preg_replace('/([\r\n])/', '', $result);
                    $result = json_decode($result, true);
                    if ($result['status'] == 1) {
                        return $result;
                    } else {
                        throw new Exception($result['result']);
                    }
                }
            }
        } catch (Exception $e) {
            $this->json_error($e->getMessage());
        }
    }

    // 获取仓库列表
    public function GetStoreList() {
        $result = $this->api('GetStoreList', array(
            'wxNum' => $this->wxNum,
        ));
        $this->json_result($result);
    }

    // 保存出库单表头
    public function AddOutBillHead() {
        $result = $this->api('AddOutBillHead', array(
            'wxNum' => $this->wxNum,
            'storeID' => $_POST['storeID'],
        ));
        $this->json_result($result);
    }

    // 获取出库单商品信息
    public function GetStoreGoodsList() {
        $result = $this->api('GetStoreGoodsList', array(
            'tid' => $_POST['tid'],
            'wxNum' => $this->wxNum,
        ));
        $this->json_result($result);
    }
    // 保存出库表单体
    public function AddOutBillList() {
        $result = $this->api('AddOutBillList', array(
            'tid' => $_POST['tid'],
            'goodsListInfo' => $_POST['goodsListInfo'],
        ));
        $this->json_result($result);
    }

}